package com.cheung.leetcode.dp;

import org.junit.jupiter.api.Test;

/**
 * @BelongsProject : java-leetcode
 * @BelongsPackage : com.cheung.leetcode.dp
 * @Author :  cheungming
 * @CreateTime : 2024-06-11 09:15:52
 * @Description : 棋盘
 * @Version : 1.0
 */
public class Code62Test {

    public int uniquePaths(int m, int n) {
        int[][] dp = new int[m][n];

        // 如果只有一行或列，只有一条路径
        for (int i = 0; i < m; i++) {
            dp[i][0] = 1;
        }
        for (int i = 0; i < n; i++) {
            dp[0][i] = 1;
        }

        // 对于其余位置，路径数等于上方路径数加上左方路径数
        for (int i = 1; i < m; i++) {
            for (int j = 1; j < n; j++) {
                dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
            }
        }

        // 返回右下角位置的路径数
        return dp[m - 1][n - 1];
    }

    @Test
    public void test1() {
        assert uniquePaths(3, 7) == 28;
    }

    @Test
    public void test2() {
        assert uniquePaths(3, 2) == 3;
    }

    @Test
    public void test3() {
        assert uniquePaths(7, 3) == 28;
    }

    @Test
    public void test4() {
        assert uniquePaths(3, 3) == 6;
    }
}
